/* $Id: ProcessStepDAOImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.dao.provider;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import ae.pcfc.etks.online.common.dao.ProcessStepDAO;
import ae.pcfc.etks.online.common.domain.ProcessStep;

@Repository
public class ProcessStepDAOImpl extends BaseDAO implements ProcessStepDAO {

	/**
	 * getProcessStepByProcessStepCode
	 * 
	 * @see ae.pcfc.etks.online.common.dao.ProcessStepDAO#getProcessStepByProcessStepCode(java.lang.String)
	 * 
	 */
	public ProcessStep getProcessStepByProcessStepCode(String processStepCode) {
		
		Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(ProcessStep.class);
		criteria.add(Restrictions.eq("processStepCode", processStepCode));		
		@SuppressWarnings("unchecked")		
		List<ProcessStep> list =  criteria.list();
		
		if(list.size() > 0)
			return list.get(0);
		else
			return null;
	}

	public ProcessStep getProcessStepByProcessCodeAndProcessStepCode(String strProcessCode, String strProcessStepCode) {
		Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(ProcessStep.class,"processStep");
		criteria.createAlias("processStep.process", "process");
		criteria.add(Restrictions.eq("process.processCode", strProcessCode));
		criteria.add(Restrictions.eq("processStep.processStepCode", strProcessStepCode));		
		@SuppressWarnings("unchecked")		
		List<ProcessStep> list =  criteria.list();
		
		if(list.size() > 0)
			return list.get(0);
		else
			return null;
	}
}
